home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: miker3@ix.netcom.com (Mike Rubenstein)
- Newsgroups: comp.lang.c
- Subject: Re: What is &Variable (declared as: char Variable[10])?
- Date: Thu, 29 Feb 1996 20:46:35 GMT
- Organization: Netcom
- Message-ID: <3135e705.79283884@nntp.ix.netcom.com>
- References: <4gqpa1$3h9@alcor.usc.edu> <4gsdno$1bg@umbc9.umbc.edu> <4gtab6$acb@ceylon.gte.com><313318b8.53776146@nntp.ix.netcom.com> <1177@altheim.win-uk.net>
- NNTP-Posting-Host: ix-dc12-23.ix.netcom.com
- X-NETCOM-Date: Thu Feb 29 12:46:36 PM PST 1996
- X-Newsreader: Forte Agent .99d/32.182
-
- broldham@altheim.win-uk.net (Brian R. Oldham) wrote:
-
- >
- > In article <313318b8.53776146@nntp.ix.netcom.com>, Mike Rubenstein (miker3@ix.netcom.com) writes:
- > >Brenda <g051286> wrote:
- > >
- > >> schlein@umbc.edu (Jonas J. Schlein) wrote:
- > >> >Abu Wawda <wawda@alcor.usc.edu> wrote:
- > >> >|> I'm having trouble understanding what the address of a static array
- > >> >|> is.
- > >> >
- > >> >I'm having trouble understanding why it matters? You almost never use the
- > >> >address of an array directly unless doing something tricky with pointers
- > >> >or with particular dimensions of a multiple dimensional array.
- > >> >
- > >> >|> For example, if I declare a variable called myarray as:
- > >> >|> char myarray[10];
- > >> >|> then what could &myarray possibly mean? myarray is not a pointer, so
- > >> >|> &myarray could not possibly be the address of the variable myarray
- > >> >|> (like it would be if I did char* myarray and then asked for &myarray).
- > >> >
- > >> >Yes it could and yes it is...'myarray' is not a pointer, but &myarray is
- > >> >a pointer to 'myarray'.
- > >>
- > >> Um, that's not correct. myarray is DEFINITELY a pointer! As declared above,
- > >> it is a constant pointer to 10 contiguous char datatypes. myarray is an
- > >> ADDRESS whereas *(myarray + 5) or myarray[5] is the 6th element in the array.
- > >> The difference between an array and something like "char *p=myarray", is that
- > >> you can say p++, but you can't say myarray++. You shouldn't say &myarray
- > >> either because myarray is a constant, but I read that on some compilers
- > >> scanf ignores the dereferencing and does not bother to warn you.
- > >
- > >NO. NO. NO. Where do people get this idea that arrays are pointers.
- > >Arrays are arrays and pointers are pointers. In many, but not all,
- > >situations an array is converted to a pointer. There are exceptions.
- > >For example sizeof myarray is 10 but sizeof p is almost certainly not
- > >10.
- > >
- > >Why shouldn't you say &myarray. It's perfectly legal C and any
- > >compiler that does not accept it is broken. &myarray is a pointer to
- > >an array of 10 char.
- > >
- > >
- > >Michael M Rubenstein
- > >
- >
- > I think Brenda is right. No-one has said that arrays are pointers, but
- > the name of an array is. It is the address of the first element of an
- > array. My understanding is that &myarray is allowable in C++, but not
- > in C. Anyone confirm this?
-
- No. The name of the array is the name of an array , not the name of a
- pointer.
-
- Again, in many cases the array is converted to a pointer in an
- expression, but there are exceptions. The operand of the address-of
- operator, &, is one of those exceptions. In that case the array is
- not converted to a pointer and the address-of operator is applied to
- the array, giving a pointer to an array.
-
-
- Michael M Rubenstein
-